// src/main/java/org/example/backend/repository/InternshipApplicationRepository.java
package org.example.backend.repository;

import org.example.backend.entity.InternshipApplication;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface InternshipApplicationRepository extends JpaRepository<InternshipApplication, Long> {
    Page<InternshipApplication> findByStudentId(Long studentId, Pageable pageable);

    List<InternshipApplication> findByPositionId(Long positionId);

    Optional<InternshipApplication> findByStudentIdAndPositionId(Long studentId, Long positionId);

    @Query("SELECT ia FROM InternshipApplication ia WHERE ia.companyId = :companyId AND (:status IS NULL OR ia.status = :status)")
    Page<InternshipApplication> findByCompanyIdAndStatus(@Param("companyId") Long companyId,
                                                        @Param("status") Integer status,
                                                        Pageable pageable);

    @Query("SELECT ia FROM InternshipApplication ia WHERE (:status IS NULL OR ia.status = :status)")
    Page<InternshipApplication> findByStatus(@Param("status") Integer status, Pageable pageable);

    Page<InternshipApplication> findByCompanyId(Long companyId, Pageable pageable);
}
